package cn.yl.caner.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import cn.yl.caner.domain.DelData;
import cn.yl.caner.utils.DataSourceUtils;
import cn.yl.caner.utils.MyDataSourceUtils;

public class DelDao {
	
	public String rePassword(DelData deldata) throws SQLException{
		//对比密码，是否正确
		Connection con = MyDataSourceUtils.getCurrentConnection();
		DataSource source = DataSourceUtils.getDataSource();
		QueryRunner qr = new QueryRunner(source);
//		System.out.println(deldata.toString());
		String sql = "select password from account where username = ?";
		String password = (String)qr.query(con,sql,new ScalarHandler(),deldata.getDel_username());
//		String password = delaccount.getDel_password();
		return password;
	}
	
	public int delAccount(DelData deldata) throws SQLException {
		//这个是删除账号的DAO层；
		Connection con = MyDataSourceUtils.getCurrentConnection();
		DataSource source = DataSourceUtils.getDataSource();
		QueryRunner qr = new QueryRunner(source);
		String sql = "delete from account where username = ?";
		int i = qr.update(con,sql,deldata.getDel_username());
		if(i == 1) {
			System.out.println("删除成功");
			return 1;
		}else {
			System.out.println("删除失败");
			return 0;
		}
	}
}
